Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

centra

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

centra

The core lightweight HTTP client for Node

  • 2.7.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
771K
increased by0.03%
Maintainers
1
Weekly downloads
 
Created

What is centra?

Centra is a lightweight HTTP client for Node.js that allows you to make HTTP requests with a simple and intuitive API. It supports various HTTP methods, setting headers, sending data, and handling responses.

What are centra's main functionalities?

Basic GET Request

This feature allows you to make a basic GET request to a specified URL and handle the response. In this example, it fetches a post from a placeholder API and logs the JSON response.

const centra = require('centra');

async function fetchData() {
  const res = await centra('https://jsonplaceholder.typicode.com/posts/1').send();
  console.log(await res.json());
}

fetchData();

POST Request with JSON Body

This feature allows you to make a POST request with a JSON body. The example sends a new post to the placeholder API and logs the response.

const centra = require('centra');

async function postData() {
  const res = await centra('https://jsonplaceholder.typicode.com/posts', 'POST')
    .body({ title: 'foo', body: 'bar', userId: 1 }, 'json')
    .send();
  console.log(await res.json());
}

postData();

Setting Headers

This feature allows you to set custom headers for your HTTP requests. The example demonstrates setting an Authorization header before making a GET request.

const centra = require('centra');

async function fetchDataWithHeaders() {
  const res = await centra('https://jsonplaceholder.typicode.com/posts/1')
    .header('Authorization', 'Bearer token')
    .send();
  console.log(await res.json());
}

fetchDataWithHeaders();

Handling Different Response Types

This feature allows you to handle different response types such as text, JSON, or buffers. The example fetches a post and logs the response as plain text.

const centra = require('centra');

async function fetchData() {
  const res = await centra('https://jsonplaceholder.typicode.com/posts/1').send();
  const text = await res.text();
  console.log(text);
}

fetchData();

Other packages similar to centra

Keywords

FAQs

Package last updated on 11 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc